import React from 'react'
// ===================================================================== Temp
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
import Delete from '#cpt/temp/Delete'
import TableControls from '#cpt/temp/TableControls'
import AddEditModal from '#cpt/temp/AddEditModal'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Box 		= $Lazy.load(()=>import('#tp/box/box'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		formData : [
			{ label: '联络人名称',  		name: 'critical_user', 		half:true, required:true },
			{ label: '危急值联络科室',  	name: 'project_id', 		half:true, required:true, type:'select', idStr:'uuid'},
			{ label: '联系电话',			name: 'critical_phone',		half:true, required:true },
			{ label: '危急值联络人邮箱',	name: 'critical_email',		half:true, required:true },
			{ label: '备注',				name: 'remark',				full:true, type:'textarea' },
		]
	}
	
	model = {}
	
	componentDidMount(){
		
	}
	
	load = hosp_id => {
		this.query = this.submit = { hosp_id }
		if(this.props.disabled){ this.setState({ selectedKeys: null }) }
		this.fetch()
	}
	
	// 获取弹窗下拉框数据
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, 'project_id', ()=>{
			$cache.then( async f => {
				// 危急值联络科室
				await $fn.setRowc(formData, 'project_id',  async () =>  f.getCache({ api: 'ke_shi'}))
				//
				this.setState({ formData })
			})
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'bs-critical-value/index')
	
	// 表单
	cols = [
		{ title: '序号', 				dataIndex: 'id', 				width:60 },
		{ title: '危急值联络人', 			dataIndex: 'critical_user', 	width:150 },
		{ title: '危急值联络科室', 		dataIndex: 'project_name', 		width:150 },
		{ title: '危急值联络电话', 		dataIndex: 'critical_phone', 	width:150 },
		{ title: '危急值联络人Email', 	dataIndex: 'critical_email', 	width:150 },
		{ title: '备注', 				dataIndex: 'remark', 			width:150 },
		TableControls.controls.call(this, { width: 120 })
	]
	// 表格操作按钮
	table_controls = (text,{ uuid }) => {
		return [
			TableControls.edit.call(this, 'bs-critical-value/info', {uuid}, {
				select: this.getModalSelect,
				disabled: this.props.disabled
			}),
			this.onDel([uuid])
		]
	}
	// 操作按钮
	controls = () => {
		return [
			Controls.add.call(this,{click:this.getModalSelect, code:false, disabled: this.props.disabled}),
			this.onDel()
		]
	}
	// 删除
	onDel = uuid => Delete.call(this, 'bs-critical-value/del', { uuid, isKeys: !uuid, disabled: this.props.disabled })
	
	render(){
		return (
			<>
				<Box title='危急值联络人' small controls={this.controls()} className='mt5 w' contentClassName={$fn.hasArray(this.state.data) ? 'pt10' : 'ptb10'}>
					{/* 表格 */}
					{ Table.call(this, { wrapStyle: {height:350} }) }
				</Box>
				{/* 添加、编辑 */}
				{ AddEditModal.call(this,{ labelWidth:'s9', width:800, api: 'bs-critical-value/add', editApi: 'bs-critical-value/edit'}) }
			</>
		)
	}
}

export default Index